import { DataSource, DataSourceOptions } from 'typeorm';
import * as dotenv from 'dotenv';
import { User } from '../entities/user.entity';
import { Role } from '../entities/role.entity';
import { Permission } from '../entities/permission.entity';
import { Project } from '../entities/project.entity';
import { ProjectMember } from '../entities/project-member.entity';
import { Task } from '../entities/task.entity';
import { TaskComment } from '../entities/task-comment.entity';
import { TaskTag } from '../entities/task-tag.entity';
import { Tag } from '../entities/tag.entity';
import { Workspace } from '../entities/workspace.entity';
import { WorkspaceMember } from '../entities/workspace-member.entity';
import { TaskCommentReply } from '../entities/task-comment-reply.entity';
import { Notification } from '../entities/notification.entity';
import { File } from '../entities/file.entity';

dotenv.config();

export const dataSourceOptions: DataSourceOptions = {
  type: 'postgres',
  host: process.env.DB_HOST || 'localhost',
  port: parseInt(process.env.DB_PORT || '5432', 10),
  username: process.env.DB_USERNAME || 'monday',
  password: process.env.DB_PASSWORD || 'monday123',
  database: process.env.DB_DATABASE || 'monday',
  entities: [
    User,
    Role,
    Permission,
    Project,
    ProjectMember,
    Task,
    TaskComment,
    TaskCommentReply,
    TaskTag,
    Tag,
    Workspace,
    WorkspaceMember,
    Notification,
    File
  ],
  migrations: ['dist/migrations/*.js'],
  synchronize: process.env.NODE_ENV !== 'production',
  logging: process.env.NODE_ENV !== 'production',
};

const dataSource = new DataSource(dataSourceOptions);
export default dataSource; 